package br.com.controler;

import br.com.modelo.DavDetalhe;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import util.JPAUtil;

/**
 *
 * @author Administrador
 */
public class DavDetalheControler {

    public static List<DavDetalhe> retornaDavEmAberto(Integer idDav) {
        EntityManager em = JPAUtil.retornarFabrica().createEntityManager();
        Query q = em.createQuery("FROM DavDetalhe d WHERE d.idDavCabecalho.id = ?");
        q.setParameter(1, idDav);
        List<DavDetalhe> list = q.getResultList();
        em.close();
        return list;
    }

    public static void deletaitens(Integer idDavAlteracao) {
        EntityManager em = JPAUtil.retornarFabrica().createEntityManager();
        Query q = em.createQuery("DELETE FROM DavDetalhe d WHERE d.idDavCabecalho.id = ?");
        q.setParameter(1, idDavAlteracao);
        q.executeUpdate();
        em.close();
    }
}
